﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 3.1
// Code is generated on: Thursday, June 23, 2011 1:28:25 PM
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version: 
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;
#if !CF
using System.Runtime.Serialization;
#endif
using System.Data;
using System.Xml.Serialization;
using MyHealthOnline.Dal.Generated;
using MyHealthOnline.Dal.Generated.FactoryClasses;
using MyHealthOnline.Dal.Generated.DaoClasses;
using MyHealthOnline.Dal.Generated.RelationClasses;
using MyHealthOnline.Dal.Generated.HelperClasses;
using MyHealthOnline.Dal.Generated.CollectionClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MyHealthOnline.Dal.Generated.EntityClasses
{
	
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END
	

	/// <summary>Entity class which represents the entity 'Question'. <br/><br/>
	/// 
	/// </summary>
	[Serializable]
	public partial class QuestionEntity : CommonEntityBase
		// __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
		// __LLBLGENPRO_USER_CODE_REGION_END
			
	{
		#region Class Member Declarations
		private MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection	_questionnaireQuestion;
		private bool	_alwaysFetchQuestionnaireQuestion, _alreadyFetchedQuestionnaireQuestion;
		private ConsultQuestionEntity _consultQuestion;
		private bool	_alwaysFetchConsultQuestion, _alreadyFetchedConsultQuestion, _consultQuestionReturnsNewIfNotFound;
		private DateQuestionEntity _dateQuestion;
		private bool	_alwaysFetchDateQuestion, _alreadyFetchedDateQuestion, _dateQuestionReturnsNewIfNotFound;
		private MultiChoiceQuestionEntity _multiChoiceQuestion;
		private bool	_alwaysFetchMultiChoiceQuestion, _alreadyFetchedMultiChoiceQuestion, _multiChoiceQuestionReturnsNewIfNotFound;
		private OpenQuestionEntity _openQuestion;
		private bool	_alwaysFetchOpenQuestion, _alreadyFetchedOpenQuestion, _openQuestionReturnsNewIfNotFound;
		private QuestionnaireEntity _questionnaire;
		private bool	_alwaysFetchQuestionnaire, _alreadyFetchedQuestionnaire, _questionnaireReturnsNewIfNotFound;

		// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
		// __LLBLGENPRO_USER_CODE_REGION_END
		
		#endregion

		#region Statics
		private static Dictionary<string, string>	_customProperties;
		private static Dictionary<string, Dictionary<string, string>>	_fieldsCustomProperties;

		/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
		public static partial class MemberNames
		{
			/// <summary>Member name QuestionnaireQuestion</summary>
			public static readonly string QuestionnaireQuestion = "QuestionnaireQuestion";
			/// <summary>Member name ConsultQuestion</summary>
			public static readonly string ConsultQuestion = "ConsultQuestion";
			/// <summary>Member name DateQuestion</summary>
			public static readonly string DateQuestion = "DateQuestion";
			/// <summary>Member name MultiChoiceQuestion</summary>
			public static readonly string MultiChoiceQuestion = "MultiChoiceQuestion";
			/// <summary>Member name OpenQuestion</summary>
			public static readonly string OpenQuestion = "OpenQuestion";
			/// <summary>Member name Questionnaire</summary>
			public static readonly string Questionnaire = "Questionnaire";
		}
		#endregion
		
		/// <summary>Static CTor for setting up custom property hashtables. Is executed before the first instance of this entity class or derived classes is constructed. </summary>
		static QuestionEntity()
		{
			SetupCustomPropertyHashtables();
		}

		/// <summary>CTor</summary>
		public QuestionEntity() : base()
		{
			InitClassEmpty(null);
		}
		
		/// <summary>CTor</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		public QuestionEntity(System.Int32 id)
		{
			InitClassFetch(id, null, null);
		}

		/// <summary>CTor</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		public QuestionEntity(System.Int32 id, IPrefetchPath prefetchPathToUse)
		{
			InitClassFetch(id, null, prefetchPathToUse);
		}

		/// <summary>CTor</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <param name="validator">The custom validator object for this QuestionEntity</param>
		public QuestionEntity(System.Int32 id, IValidator validator)
		{
			InitClassFetch(id, validator, null);
		}

		/// <summary>Private CTor for deserialization</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		protected QuestionEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			_questionnaireQuestion = (MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection)info.GetValue("_questionnaireQuestion", typeof(MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection));
			_alwaysFetchQuestionnaireQuestion = info.GetBoolean("_alwaysFetchQuestionnaireQuestion");
			_alreadyFetchedQuestionnaireQuestion = info.GetBoolean("_alreadyFetchedQuestionnaireQuestion");
			_consultQuestion = (ConsultQuestionEntity)info.GetValue("_consultQuestion", typeof(ConsultQuestionEntity));
			if(_consultQuestion!=null)
			{
				_consultQuestion.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_consultQuestionReturnsNewIfNotFound = info.GetBoolean("_consultQuestionReturnsNewIfNotFound");
			_alwaysFetchConsultQuestion = info.GetBoolean("_alwaysFetchConsultQuestion");
			_alreadyFetchedConsultQuestion = info.GetBoolean("_alreadyFetchedConsultQuestion");

			_dateQuestion = (DateQuestionEntity)info.GetValue("_dateQuestion", typeof(DateQuestionEntity));
			if(_dateQuestion!=null)
			{
				_dateQuestion.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_dateQuestionReturnsNewIfNotFound = info.GetBoolean("_dateQuestionReturnsNewIfNotFound");
			_alwaysFetchDateQuestion = info.GetBoolean("_alwaysFetchDateQuestion");
			_alreadyFetchedDateQuestion = info.GetBoolean("_alreadyFetchedDateQuestion");

			_multiChoiceQuestion = (MultiChoiceQuestionEntity)info.GetValue("_multiChoiceQuestion", typeof(MultiChoiceQuestionEntity));
			if(_multiChoiceQuestion!=null)
			{
				_multiChoiceQuestion.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_multiChoiceQuestionReturnsNewIfNotFound = info.GetBoolean("_multiChoiceQuestionReturnsNewIfNotFound");
			_alwaysFetchMultiChoiceQuestion = info.GetBoolean("_alwaysFetchMultiChoiceQuestion");
			_alreadyFetchedMultiChoiceQuestion = info.GetBoolean("_alreadyFetchedMultiChoiceQuestion");

			_openQuestion = (OpenQuestionEntity)info.GetValue("_openQuestion", typeof(OpenQuestionEntity));
			if(_openQuestion!=null)
			{
				_openQuestion.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_openQuestionReturnsNewIfNotFound = info.GetBoolean("_openQuestionReturnsNewIfNotFound");
			_alwaysFetchOpenQuestion = info.GetBoolean("_alwaysFetchOpenQuestion");
			_alreadyFetchedOpenQuestion = info.GetBoolean("_alreadyFetchedOpenQuestion");

			_questionnaire = (QuestionnaireEntity)info.GetValue("_questionnaire", typeof(QuestionnaireEntity));
			if(_questionnaire!=null)
			{
				_questionnaire.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_questionnaireReturnsNewIfNotFound = info.GetBoolean("_questionnaireReturnsNewIfNotFound");
			_alwaysFetchQuestionnaire = info.GetBoolean("_alwaysFetchQuestionnaire");
			_alreadyFetchedQuestionnaire = info.GetBoolean("_alreadyFetchedQuestionnaire");
			this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
			
		}
		

		/// <summary> Will perform post-ReadXml actions</summary>
		protected override void PostReadXmlFixups()
		{
			_alreadyFetchedQuestionnaireQuestion = (_questionnaireQuestion.Count > 0);
			_alreadyFetchedConsultQuestion = (_consultQuestion != null);
			_alreadyFetchedDateQuestion = (_dateQuestion != null);
			_alreadyFetchedMultiChoiceQuestion = (_multiChoiceQuestion != null);
			_alreadyFetchedOpenQuestion = (_openQuestion != null);
			_alreadyFetchedQuestionnaire = (_questionnaire != null);
		}
				
		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		protected override RelationCollection GetRelationsForFieldOfType(string fieldName)
		{
			return GetRelationsForField(fieldName);
		}

		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		internal static RelationCollection GetRelationsForField(string fieldName)
		{
			RelationCollection toReturn = new RelationCollection();
			switch(fieldName)
			{
				case "QuestionnaireQuestion":
					toReturn.Add(Relations.QuestionnaireQuestionEntityUsingQuestionId);
					break;
				case "ConsultQuestion":
					toReturn.Add(Relations.ConsultQuestionEntityUsingQuestionId);
					break;
				case "DateQuestion":
					toReturn.Add(Relations.DateQuestionEntityUsingQuestionId);
					break;
				case "MultiChoiceQuestion":
					toReturn.Add(Relations.MultiChoiceQuestionEntityUsingQuestionId);
					break;
				case "OpenQuestion":
					toReturn.Add(Relations.OpenQuestionEntityUsingQuestionId);
					break;
				case "Questionnaire":
					toReturn.Add(Relations.QuestionnaireEntityUsingQuestionId);
					break;
				default:
					break;				
			}
			return toReturn;
		}



		/// <summary> ISerializable member. Does custom serialization so event handlers do not get serialized.</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("_questionnaireQuestion", (!this.MarkedForDeletion?_questionnaireQuestion:null));
			info.AddValue("_alwaysFetchQuestionnaireQuestion", _alwaysFetchQuestionnaireQuestion);
			info.AddValue("_alreadyFetchedQuestionnaireQuestion", _alreadyFetchedQuestionnaireQuestion);

			info.AddValue("_consultQuestion", (!this.MarkedForDeletion?_consultQuestion:null));
			info.AddValue("_consultQuestionReturnsNewIfNotFound", _consultQuestionReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchConsultQuestion", _alwaysFetchConsultQuestion);
			info.AddValue("_alreadyFetchedConsultQuestion", _alreadyFetchedConsultQuestion);

			info.AddValue("_dateQuestion", (!this.MarkedForDeletion?_dateQuestion:null));
			info.AddValue("_dateQuestionReturnsNewIfNotFound", _dateQuestionReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchDateQuestion", _alwaysFetchDateQuestion);
			info.AddValue("_alreadyFetchedDateQuestion", _alreadyFetchedDateQuestion);

			info.AddValue("_multiChoiceQuestion", (!this.MarkedForDeletion?_multiChoiceQuestion:null));
			info.AddValue("_multiChoiceQuestionReturnsNewIfNotFound", _multiChoiceQuestionReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchMultiChoiceQuestion", _alwaysFetchMultiChoiceQuestion);
			info.AddValue("_alreadyFetchedMultiChoiceQuestion", _alreadyFetchedMultiChoiceQuestion);

			info.AddValue("_openQuestion", (!this.MarkedForDeletion?_openQuestion:null));
			info.AddValue("_openQuestionReturnsNewIfNotFound", _openQuestionReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchOpenQuestion", _alwaysFetchOpenQuestion);
			info.AddValue("_alreadyFetchedOpenQuestion", _alreadyFetchedOpenQuestion);

			info.AddValue("_questionnaire", (!this.MarkedForDeletion?_questionnaire:null));
			info.AddValue("_questionnaireReturnsNewIfNotFound", _questionnaireReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchQuestionnaire", _alwaysFetchQuestionnaire);
			info.AddValue("_alreadyFetchedQuestionnaire", _alreadyFetchedQuestionnaire);

			// __LLBLGENPRO_USER_CODE_REGION_START GetObjectInfo
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			base.GetObjectData(info, context);
		}
		
		/// <summary> Sets the related entity property to the entity specified. If the property is a collection, it will add the entity specified to that collection.</summary>
		/// <param name="propertyName">Name of the property.</param>
		/// <param name="entity">Entity to set as an related entity</param>
		/// <remarks>Used by prefetch path logic.</remarks>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void SetRelatedEntityProperty(string propertyName, IEntity entity)
		{
			switch(propertyName)
			{
				case "QuestionnaireQuestion":
					_alreadyFetchedQuestionnaireQuestion = true;
					if(entity!=null)
					{
						this.QuestionnaireQuestion.Add((QuestionnaireQuestionEntity)entity);
					}
					break;
				case "ConsultQuestion":
					_alreadyFetchedConsultQuestion = true;
					this.ConsultQuestion = (ConsultQuestionEntity)entity;
					break;
				case "DateQuestion":
					_alreadyFetchedDateQuestion = true;
					this.DateQuestion = (DateQuestionEntity)entity;
					break;
				case "MultiChoiceQuestion":
					_alreadyFetchedMultiChoiceQuestion = true;
					this.MultiChoiceQuestion = (MultiChoiceQuestionEntity)entity;
					break;
				case "OpenQuestion":
					_alreadyFetchedOpenQuestion = true;
					this.OpenQuestion = (OpenQuestionEntity)entity;
					break;
				case "Questionnaire":
					_alreadyFetchedQuestionnaire = true;
					this.Questionnaire = (QuestionnaireEntity)entity;
					break;
				default:
					this.OnSetRelatedEntityProperty(propertyName, entity);
					break;
			}
		}

		/// <summary> Sets the internal parameter related to the fieldname passed to the instance relatedEntity. </summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void SetRelatedEntity(IEntity relatedEntity, string fieldName)
		{
			switch(fieldName)
			{
				case "QuestionnaireQuestion":
					_questionnaireQuestion.Add((QuestionnaireQuestionEntity)relatedEntity);
					break;
				case "ConsultQuestion":
					SetupSyncConsultQuestion(relatedEntity);
					break;
				case "DateQuestion":
					SetupSyncDateQuestion(relatedEntity);
					break;
				case "MultiChoiceQuestion":
					SetupSyncMultiChoiceQuestion(relatedEntity);
					break;
				case "OpenQuestion":
					SetupSyncOpenQuestion(relatedEntity);
					break;
				case "Questionnaire":
					SetupSyncQuestionnaire(relatedEntity);
					break;
				default:
					break;
			}
		}
		
		/// <summary> Unsets the internal parameter related to the fieldname passed to the instance relatedEntity. Reverses the actions taken by SetRelatedEntity() </summary>
		/// <param name="relatedEntity">Instance to unset as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		/// <param name="signalRelatedEntityManyToOne">if set to true it will notify the manytoone side, if applicable.</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void UnsetRelatedEntity(IEntity relatedEntity, string fieldName, bool signalRelatedEntityManyToOne)
		{
			switch(fieldName)
			{
				case "QuestionnaireQuestion":
					this.PerformRelatedEntityRemoval(_questionnaireQuestion, relatedEntity, signalRelatedEntityManyToOne);
					break;
				case "ConsultQuestion":
					DesetupSyncConsultQuestion(false, true);
					break;
				case "DateQuestion":
					DesetupSyncDateQuestion(false, true);
					break;
				case "MultiChoiceQuestion":
					DesetupSyncMultiChoiceQuestion(false, true);
					break;
				case "OpenQuestion":
					DesetupSyncOpenQuestion(false, true);
					break;
				case "Questionnaire":
					DesetupSyncQuestionnaire(false, true);
					break;
				default:
					break;
			}
		}

		/// <summary> Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields). These entities will have to be persisted after this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		protected override List<IEntity> GetDependingRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();
			if(_consultQuestion!=null)
			{
				toReturn.Add(_consultQuestion);
			}
			if(_dateQuestion!=null)
			{
				toReturn.Add(_dateQuestion);
			}
			if(_multiChoiceQuestion!=null)
			{
				toReturn.Add(_multiChoiceQuestion);
			}
			if(_openQuestion!=null)
			{
				toReturn.Add(_openQuestion);
			}
			if(_questionnaire!=null)
			{
				toReturn.Add(_questionnaire);
			}
			return toReturn;
		}
		
		/// <summary> Gets a collection of related entities referenced by this entity which this entity depends on (this entity is the FK side of their PK fields). These entities will have to be persisted before this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		protected override List<IEntity> GetDependentRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();
			return toReturn;
		}
		
		/// <summary> Gets a List of all entity collections stored as member variables in this entity. Only 1:n related collections are returned.</summary>
		/// <returns>Collection with 0 or more IEntityCollection objects, referenced by this entity</returns>
		protected override List<IEntityCollection> GetMemberEntityCollections()
		{
			List<IEntityCollection> toReturn = new List<IEntityCollection>();
			toReturn.Add(_questionnaireQuestion);

			return toReturn;
		}


		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id)
		{
			return FetchUsingPK(id, null, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse)
		{
			return FetchUsingPK(id, prefetchPathToUse, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse)
		{
			return FetchUsingPK(id, prefetchPathToUse, contextToUse, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			return Fetch(id, prefetchPathToUse, contextToUse, excludedIncludedFields);
		}

		/// <summary> Refetches the Entity from the persistent storage. Refetch is used to re-load an Entity which is marked "Out-of-sync", due to a save action. Refetching an empty Entity has no effect. </summary>
		/// <returns>true if Refetch succeeded, false otherwise</returns>
		public override bool Refetch()
		{
			return Fetch(this.Id, null, null, null);
		}


				
		/// <summary>Gets a list of all the EntityRelation objects the type of this instance has.</summary>
		/// <returns>A list of all the EntityRelation objects the type of this instance has. Hierarchy relations are excluded.</returns>
		protected override List<IEntityRelation> GetAllRelations()
		{
			return new QuestionRelations().GetAllRelations();
		}

		/// <summary> Retrieves all related entities of type 'QuestionnaireQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'QuestionnaireQuestionEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection GetMultiQuestionnaireQuestion(bool forceFetch)
		{
			return GetMultiQuestionnaireQuestion(forceFetch, _questionnaireQuestion.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'QuestionnaireQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'QuestionnaireQuestionEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection GetMultiQuestionnaireQuestion(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiQuestionnaireQuestion(forceFetch, _questionnaireQuestion.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'QuestionnaireQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection GetMultiQuestionnaireQuestion(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiQuestionnaireQuestion(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'QuestionnaireQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection GetMultiQuestionnaireQuestion(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedQuestionnaireQuestion || forceFetch || _alwaysFetchQuestionnaireQuestion) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode)
			{
				AddToTransactionIfNecessary(_questionnaireQuestion);
				_questionnaireQuestion.SuppressClearInGetMulti=!forceFetch;
				_questionnaireQuestion.EntityFactoryToUse = entityFactoryToUse;
				_questionnaireQuestion.GetMultiManyToOne(this, null, filter);
				_questionnaireQuestion.SuppressClearInGetMulti=false;
				_alreadyFetchedQuestionnaireQuestion = true;
			}
			return _questionnaireQuestion;
		}

		/// <summary> Sets the collection parameters for the collection for 'QuestionnaireQuestion'. These settings will be taken into account
		/// when the property QuestionnaireQuestion is requested or GetMultiQuestionnaireQuestion is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersQuestionnaireQuestion(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_questionnaireQuestion.SortClauses=sortClauses;
			_questionnaireQuestion.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves the related entity of type 'ConsultQuestionEntity', using a relation of type '1:1'</summary>
		/// <returns>A fetched entity of type 'ConsultQuestionEntity' which is related to this entity.</returns>
		public ConsultQuestionEntity GetSingleConsultQuestion()
		{
			return GetSingleConsultQuestion(false);
		}
		
		/// <summary> Retrieves the related entity of type 'ConsultQuestionEntity', using a relation of type '1:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'ConsultQuestionEntity' which is related to this entity.</returns>
		public virtual ConsultQuestionEntity GetSingleConsultQuestion(bool forceFetch)
		{
			if( ( !_alreadyFetchedConsultQuestion || forceFetch || _alwaysFetchConsultQuestion) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode )
			{
				bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.ConsultQuestionEntityUsingQuestionId);
				ConsultQuestionEntity newEntity = new ConsultQuestionEntity();
				bool fetchResult = false;
				if(performLazyLoading)
				{
					AddToTransactionIfNecessary(newEntity);
					fetchResult = newEntity.FetchUsingUCQuestionId(this.Id);
				}
				if(fetchResult)
				{
					newEntity = (ConsultQuestionEntity)GetFromActiveContext(newEntity);
				}
				else
				{
					if(!_consultQuestionReturnsNewIfNotFound)
					{
						RemoveFromTransactionIfNecessary(newEntity);
						newEntity = null;
					}
				}
				this.ConsultQuestion = newEntity;
				_alreadyFetchedConsultQuestion = fetchResult;
			}
			return _consultQuestion;
		}

		/// <summary> Retrieves the related entity of type 'DateQuestionEntity', using a relation of type '1:1'</summary>
		/// <returns>A fetched entity of type 'DateQuestionEntity' which is related to this entity.</returns>
		public DateQuestionEntity GetSingleDateQuestion()
		{
			return GetSingleDateQuestion(false);
		}
		
		/// <summary> Retrieves the related entity of type 'DateQuestionEntity', using a relation of type '1:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'DateQuestionEntity' which is related to this entity.</returns>
		public virtual DateQuestionEntity GetSingleDateQuestion(bool forceFetch)
		{
			if( ( !_alreadyFetchedDateQuestion || forceFetch || _alwaysFetchDateQuestion) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode )
			{
				bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.DateQuestionEntityUsingQuestionId);
				DateQuestionEntity newEntity = new DateQuestionEntity();
				bool fetchResult = false;
				if(performLazyLoading)
				{
					AddToTransactionIfNecessary(newEntity);
					fetchResult = newEntity.FetchUsingUCQuestionId(this.Id);
				}
				if(fetchResult)
				{
					newEntity = (DateQuestionEntity)GetFromActiveContext(newEntity);
				}
				else
				{
					if(!_dateQuestionReturnsNewIfNotFound)
					{
						RemoveFromTransactionIfNecessary(newEntity);
						newEntity = null;
					}
				}
				this.DateQuestion = newEntity;
				_alreadyFetchedDateQuestion = fetchResult;
			}
			return _dateQuestion;
		}

		/// <summary> Retrieves the related entity of type 'MultiChoiceQuestionEntity', using a relation of type '1:1'</summary>
		/// <returns>A fetched entity of type 'MultiChoiceQuestionEntity' which is related to this entity.</returns>
		public MultiChoiceQuestionEntity GetSingleMultiChoiceQuestion()
		{
			return GetSingleMultiChoiceQuestion(false);
		}
		
		/// <summary> Retrieves the related entity of type 'MultiChoiceQuestionEntity', using a relation of type '1:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'MultiChoiceQuestionEntity' which is related to this entity.</returns>
		public virtual MultiChoiceQuestionEntity GetSingleMultiChoiceQuestion(bool forceFetch)
		{
			if( ( !_alreadyFetchedMultiChoiceQuestion || forceFetch || _alwaysFetchMultiChoiceQuestion) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode )
			{
				bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.MultiChoiceQuestionEntityUsingQuestionId);
				MultiChoiceQuestionEntity newEntity = new MultiChoiceQuestionEntity();
				bool fetchResult = false;
				if(performLazyLoading)
				{
					AddToTransactionIfNecessary(newEntity);
					fetchResult = newEntity.FetchUsingUCQuestionId(this.Id);
				}
				if(fetchResult)
				{
					newEntity = (MultiChoiceQuestionEntity)GetFromActiveContext(newEntity);
				}
				else
				{
					if(!_multiChoiceQuestionReturnsNewIfNotFound)
					{
						RemoveFromTransactionIfNecessary(newEntity);
						newEntity = null;
					}
				}
				this.MultiChoiceQuestion = newEntity;
				_alreadyFetchedMultiChoiceQuestion = fetchResult;
			}
			return _multiChoiceQuestion;
		}

		/// <summary> Retrieves the related entity of type 'OpenQuestionEntity', using a relation of type '1:1'</summary>
		/// <returns>A fetched entity of type 'OpenQuestionEntity' which is related to this entity.</returns>
		public OpenQuestionEntity GetSingleOpenQuestion()
		{
			return GetSingleOpenQuestion(false);
		}
		
		/// <summary> Retrieves the related entity of type 'OpenQuestionEntity', using a relation of type '1:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'OpenQuestionEntity' which is related to this entity.</returns>
		public virtual OpenQuestionEntity GetSingleOpenQuestion(bool forceFetch)
		{
			if( ( !_alreadyFetchedOpenQuestion || forceFetch || _alwaysFetchOpenQuestion) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode )
			{
				bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.OpenQuestionEntityUsingQuestionId);
				OpenQuestionEntity newEntity = new OpenQuestionEntity();
				bool fetchResult = false;
				if(performLazyLoading)
				{
					AddToTransactionIfNecessary(newEntity);
					fetchResult = newEntity.FetchUsingUCQuestionId(this.Id);
				}
				if(fetchResult)
				{
					newEntity = (OpenQuestionEntity)GetFromActiveContext(newEntity);
				}
				else
				{
					if(!_openQuestionReturnsNewIfNotFound)
					{
						RemoveFromTransactionIfNecessary(newEntity);
						newEntity = null;
					}
				}
				this.OpenQuestion = newEntity;
				_alreadyFetchedOpenQuestion = fetchResult;
			}
			return _openQuestion;
		}

		/// <summary> Retrieves the related entity of type 'QuestionnaireEntity', using a relation of type '1:1'</summary>
		/// <returns>A fetched entity of type 'QuestionnaireEntity' which is related to this entity.</returns>
		public QuestionnaireEntity GetSingleQuestionnaire()
		{
			return GetSingleQuestionnaire(false);
		}
		
		/// <summary> Retrieves the related entity of type 'QuestionnaireEntity', using a relation of type '1:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'QuestionnaireEntity' which is related to this entity.</returns>
		public virtual QuestionnaireEntity GetSingleQuestionnaire(bool forceFetch)
		{
			if( ( !_alreadyFetchedQuestionnaire || forceFetch || _alwaysFetchQuestionnaire) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode )
			{
				bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.QuestionnaireEntityUsingQuestionId);
				QuestionnaireEntity newEntity = new QuestionnaireEntity();
				bool fetchResult = false;
				if(performLazyLoading)
				{
					AddToTransactionIfNecessary(newEntity);
					fetchResult = newEntity.FetchUsingUCQuestionId(this.Id);
				}
				if(fetchResult)
				{
					newEntity = (QuestionnaireEntity)GetFromActiveContext(newEntity);
				}
				else
				{
					if(!_questionnaireReturnsNewIfNotFound)
					{
						RemoveFromTransactionIfNecessary(newEntity);
						newEntity = null;
					}
				}
				this.Questionnaire = newEntity;
				_alreadyFetchedQuestionnaire = fetchResult;
			}
			return _questionnaire;
		}


		/// <summary>Gets all related data objects, stored by name. The name is the field name mapped onto the relation for that particular data element.</summary>
		/// <returns>Dictionary with per name the related referenced data element, which can be an entity collection or an entity or null</returns>
		protected override Dictionary<string, object> GetRelatedData()
		{
			Dictionary<string, object> toReturn = new Dictionary<string, object>();
			toReturn.Add("QuestionnaireQuestion", _questionnaireQuestion);
			toReturn.Add("ConsultQuestion", _consultQuestion);
			toReturn.Add("DateQuestion", _dateQuestion);
			toReturn.Add("MultiChoiceQuestion", _multiChoiceQuestion);
			toReturn.Add("OpenQuestion", _openQuestion);
			toReturn.Add("Questionnaire", _questionnaire);
			return toReturn;
		}
	
		/// <summary> Initializes the class with empty data, as if it is a new Entity.</summary>
		/// <param name="validatorToUse">Validator to use.</param>
		private void InitClassEmpty(IValidator validatorToUse)
		{
			OnInitializing();
			this.Fields = CreateFields();
			this.Validator = validatorToUse;
			InitClassMembers();

			// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
			// __LLBLGENPRO_USER_CODE_REGION_END
			

			OnInitialized();
		}		

		/// <summary> Initializes the the entity and fetches the data related to the entity in this entity.</summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <param name="validator">The validator object for this QuestionEntity</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		private void InitClassFetch(System.Int32 id, IValidator validator, IPrefetchPath prefetchPathToUse)
		{
			OnInitializing();
			this.Validator = validator;
			this.Fields = CreateFields();
			InitClassMembers();	
			Fetch(id, prefetchPathToUse, null, null);

			// __LLBLGENPRO_USER_CODE_REGION_START InitClassFetch
			// __LLBLGENPRO_USER_CODE_REGION_END
			

			OnInitialized();
		}

		/// <summary> Initializes the class members</summary>
		private void InitClassMembers()
		{

			_questionnaireQuestion = new MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection();
			_questionnaireQuestion.SetContainingEntityInfo(this, "Question");
			_consultQuestionReturnsNewIfNotFound = false;
			_dateQuestionReturnsNewIfNotFound = false;
			_multiChoiceQuestionReturnsNewIfNotFound = false;
			_openQuestionReturnsNewIfNotFound = false;
			_questionnaireReturnsNewIfNotFound = false;
			PerformDependencyInjection();

			// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			OnInitClassMembersComplete();
		}

		#region Custom Property Hashtable Setup
		/// <summary> Initializes the hashtables for the entity type and entity field custom properties. </summary>
		private static void SetupCustomPropertyHashtables()
		{
			_customProperties = new Dictionary<string, string>();
			_fieldsCustomProperties = new Dictionary<string, Dictionary<string, string>>();
			Dictionary<string, string> fieldHashtable;
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("AnswerDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("Id", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("IsDatabaseQuestion", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("QuestionDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("QuestionText", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("Type", fieldHashtable);
		}
		#endregion

		/// <summary> Removes the sync logic for member _consultQuestion</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncConsultQuestion(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _consultQuestion, new PropertyChangedEventHandler( OnConsultQuestionPropertyChanged ), "ConsultQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.ConsultQuestionEntityUsingQuestionIdStatic, false, signalRelatedEntity, "Question", false, new int[] { (int)QuestionFieldIndex.Id } );
			_consultQuestion = null;
		}
	
		/// <summary> setups the sync logic for member _consultQuestion</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncConsultQuestion(IEntity relatedEntity)
		{
			if(_consultQuestion!=relatedEntity)
			{
				DesetupSyncConsultQuestion(true, true);
				_consultQuestion = (ConsultQuestionEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _consultQuestion, new PropertyChangedEventHandler( OnConsultQuestionPropertyChanged ), "ConsultQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.ConsultQuestionEntityUsingQuestionIdStatic, false, ref _alreadyFetchedConsultQuestion, new string[] {  } );
			}
		}
		
		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnConsultQuestionPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				default:
					break;
			}
		}

		/// <summary> Removes the sync logic for member _dateQuestion</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncDateQuestion(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _dateQuestion, new PropertyChangedEventHandler( OnDateQuestionPropertyChanged ), "DateQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.DateQuestionEntityUsingQuestionIdStatic, false, signalRelatedEntity, "Question", false, new int[] { (int)QuestionFieldIndex.Id } );
			_dateQuestion = null;
		}
	
		/// <summary> setups the sync logic for member _dateQuestion</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncDateQuestion(IEntity relatedEntity)
		{
			if(_dateQuestion!=relatedEntity)
			{
				DesetupSyncDateQuestion(true, true);
				_dateQuestion = (DateQuestionEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _dateQuestion, new PropertyChangedEventHandler( OnDateQuestionPropertyChanged ), "DateQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.DateQuestionEntityUsingQuestionIdStatic, false, ref _alreadyFetchedDateQuestion, new string[] { "DateAnswer" } );
			}
		}
		
		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnDateQuestionPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				case "Answer":
					this.OnPropertyChanged("DateAnswer");
					break;
				default:
					break;
			}
		}

		/// <summary> Removes the sync logic for member _multiChoiceQuestion</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncMultiChoiceQuestion(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _multiChoiceQuestion, new PropertyChangedEventHandler( OnMultiChoiceQuestionPropertyChanged ), "MultiChoiceQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.MultiChoiceQuestionEntityUsingQuestionIdStatic, false, signalRelatedEntity, "Question", false, new int[] { (int)QuestionFieldIndex.Id } );
			_multiChoiceQuestion = null;
		}
	
		/// <summary> setups the sync logic for member _multiChoiceQuestion</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncMultiChoiceQuestion(IEntity relatedEntity)
		{
			if(_multiChoiceQuestion!=relatedEntity)
			{
				DesetupSyncMultiChoiceQuestion(true, true);
				_multiChoiceQuestion = (MultiChoiceQuestionEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _multiChoiceQuestion, new PropertyChangedEventHandler( OnMultiChoiceQuestionPropertyChanged ), "MultiChoiceQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.MultiChoiceQuestionEntityUsingQuestionIdStatic, false, ref _alreadyFetchedMultiChoiceQuestion, new string[] { "MultiAnswer", "MultiChoices", "MultiPatientRemarks" } );
			}
		}
		
		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnMultiChoiceQuestionPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				case "Answer":
					this.OnPropertyChanged("MultiAnswer");
					break;
				case "Choices":
					this.OnPropertyChanged("MultiChoices");
					break;
				case "PatientRemarks":
					this.OnPropertyChanged("MultiPatientRemarks");
					break;
				default:
					break;
			}
		}

		/// <summary> Removes the sync logic for member _openQuestion</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncOpenQuestion(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _openQuestion, new PropertyChangedEventHandler( OnOpenQuestionPropertyChanged ), "OpenQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.OpenQuestionEntityUsingQuestionIdStatic, false, signalRelatedEntity, "Question", false, new int[] { (int)QuestionFieldIndex.Id } );
			_openQuestion = null;
		}
	
		/// <summary> setups the sync logic for member _openQuestion</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncOpenQuestion(IEntity relatedEntity)
		{
			if(_openQuestion!=relatedEntity)
			{
				DesetupSyncOpenQuestion(true, true);
				_openQuestion = (OpenQuestionEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _openQuestion, new PropertyChangedEventHandler( OnOpenQuestionPropertyChanged ), "OpenQuestion", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.OpenQuestionEntityUsingQuestionIdStatic, false, ref _alreadyFetchedOpenQuestion, new string[] { "OpenAnswer" } );
			}
		}
		
		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnOpenQuestionPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				case "Answer":
					this.OnPropertyChanged("OpenAnswer");
					break;
				default:
					break;
			}
		}

		/// <summary> Removes the sync logic for member _questionnaire</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncQuestionnaire(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _questionnaire, new PropertyChangedEventHandler( OnQuestionnairePropertyChanged ), "Questionnaire", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.QuestionnaireEntityUsingQuestionIdStatic, false, signalRelatedEntity, "Question", false, new int[] { (int)QuestionFieldIndex.Id } );
			_questionnaire = null;
		}
	
		/// <summary> setups the sync logic for member _questionnaire</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncQuestionnaire(IEntity relatedEntity)
		{
			if(_questionnaire!=relatedEntity)
			{
				DesetupSyncQuestionnaire(true, true);
				_questionnaire = (QuestionnaireEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _questionnaire, new PropertyChangedEventHandler( OnQuestionnairePropertyChanged ), "Questionnaire", MyHealthOnline.Dal.Generated.RelationClasses.StaticQuestionRelations.QuestionnaireEntityUsingQuestionIdStatic, false, ref _alreadyFetchedQuestionnaire, new string[] {  } );
			}
		}
		
		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnQuestionnairePropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				default:
					break;
			}
		}

		/// <summary> Fetches the entity from the persistent storage. Fetch simply reads the entity into an EntityFields object. </summary>
		/// <param name="id">PK value for Question which data should be fetched into this Question object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		private bool Fetch(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			try
			{
				OnFetch();
				this.Fields[(int)QuestionFieldIndex.Id].ForcedCurrentValueWrite(id);
				CreateDAOInstance().FetchExisting(this, this.Transaction, prefetchPathToUse, contextToUse, excludedIncludedFields);
				return (this.Fields.State == EntityState.Fetched);
			}
			finally
			{
				OnFetchComplete();
			}
		}

		/// <summary> Creates the DAO instance for this type</summary>
		/// <returns></returns>
		protected override IDao CreateDAOInstance()
		{
			return DAOFactory.CreateQuestionDAO();
		}
		
		/// <summary> Creates the entity factory for this type.</summary>
		/// <returns></returns>
		protected override IEntityFactory CreateEntityFactory()
		{
			return new QuestionEntityFactory();
		}

		#region Class Property Declarations
		/// <summary> The relations object holding all relations of this entity with other entity classes.</summary>
		public  static QuestionRelations Relations
		{
			get	{ return new QuestionRelations(); }
		}
		
		/// <summary> The custom properties for this entity type.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, string> CustomProperties
		{
			get { return _customProperties;}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'QuestionnaireQuestion' for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathQuestionnaireQuestion
		{
			get { return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection(), (IEntityRelation)GetRelationsForField("QuestionnaireQuestion")[0], (int)MyHealthOnline.Dal.Generated.EntityType.QuestionEntity, (int)MyHealthOnline.Dal.Generated.EntityType.QuestionnaireQuestionEntity, 0, null, null, null, "QuestionnaireQuestion", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany); }
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'ConsultQuestion'  for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathConsultQuestion
		{
			get	{ return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection(), (IEntityRelation)GetRelationsForField("ConsultQuestion")[0], (int)MyHealthOnline.Dal.Generated.EntityType.QuestionEntity, (int)MyHealthOnline.Dal.Generated.EntityType.ConsultQuestionEntity, 0, null, null, null, "ConsultQuestion", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToOne);	}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'DateQuestion'  for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathDateQuestion
		{
			get	{ return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.DateQuestionCollection(), (IEntityRelation)GetRelationsForField("DateQuestion")[0], (int)MyHealthOnline.Dal.Generated.EntityType.QuestionEntity, (int)MyHealthOnline.Dal.Generated.EntityType.DateQuestionEntity, 0, null, null, null, "DateQuestion", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToOne);	}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'MultiChoiceQuestion'  for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathMultiChoiceQuestion
		{
			get	{ return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.MultiChoiceQuestionCollection(), (IEntityRelation)GetRelationsForField("MultiChoiceQuestion")[0], (int)MyHealthOnline.Dal.Generated.EntityType.QuestionEntity, (int)MyHealthOnline.Dal.Generated.EntityType.MultiChoiceQuestionEntity, 0, null, null, null, "MultiChoiceQuestion", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToOne);	}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'OpenQuestion'  for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathOpenQuestion
		{
			get	{ return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.OpenQuestionCollection(), (IEntityRelation)GetRelationsForField("OpenQuestion")[0], (int)MyHealthOnline.Dal.Generated.EntityType.QuestionEntity, (int)MyHealthOnline.Dal.Generated.EntityType.OpenQuestionEntity, 0, null, null, null, "OpenQuestion", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToOne);	}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Questionnaire'  for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathQuestionnaire
		{
			get	{ return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireCollection(), (IEntityRelation)GetRelationsForField("Questionnaire")[0], (int)MyHealthOnline.Dal.Generated.EntityType.QuestionEntity, (int)MyHealthOnline.Dal.Generated.EntityType.QuestionnaireEntity, 0, null, null, null, "Questionnaire", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToOne);	}
		}

		/// <summary>Returns the full name for this entity, which is important for the DAO to find back persistence info for this entity.</summary>
		[Browsable(false), XmlIgnore]
		protected override string LLBLGenProEntityName
		{
			get { return "QuestionEntity";}
		}

		/// <summary> The custom properties for the type of this entity instance.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		protected override Dictionary<string, string> CustomPropertiesOfType
		{
			get { return CustomProperties;}
		}

		/// <summary> The custom properties for the fields of this entity type. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, Dictionary<string, string>> FieldsCustomProperties
		{
			get { return _fieldsCustomProperties;}
		}

		/// <summary> The custom properties for the fields of the type of this entity instance. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		protected override Dictionary<string, Dictionary<string, string>> FieldsCustomPropertiesOfType
		{
			get { return FieldsCustomProperties;}
		}

		/// <summary> The AnswerDate property of the Entity Question<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Question"."AnswerDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.DateTime> AnswerDate
		{
			get { return (Nullable<System.DateTime>)GetValue((int)QuestionFieldIndex.AnswerDate, false); }
			set	{ SetValue((int)QuestionFieldIndex.AnswerDate, value, true); }
		}

		/// <summary> The Id property of the Entity Question<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Question"."Id"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
		public virtual System.Int32 Id
		{
			get { return (System.Int32)GetValue((int)QuestionFieldIndex.Id, true); }
			set	{ SetValue((int)QuestionFieldIndex.Id, value, true); }
		}

		/// <summary> The IsDatabaseQuestion property of the Entity Question<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Question"."IsDatabaseQuestion"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean IsDatabaseQuestion
		{
			get { return (System.Boolean)GetValue((int)QuestionFieldIndex.IsDatabaseQuestion, true); }
			set	{ SetValue((int)QuestionFieldIndex.IsDatabaseQuestion, value, true); }
		}

		/// <summary> The QuestionDate property of the Entity Question<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Question"."QuestionDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.DateTime QuestionDate
		{
			get { return (System.DateTime)GetValue((int)QuestionFieldIndex.QuestionDate, true); }
			set	{ SetValue((int)QuestionFieldIndex.QuestionDate, value, true); }
		}

		/// <summary> The QuestionText property of the Entity Question<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Question"."QuestionText"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String QuestionText
		{
			get { return (System.String)GetValue((int)QuestionFieldIndex.QuestionText, true); }
			set	{ SetValue((int)QuestionFieldIndex.QuestionText, value, true); }
		}

		/// <summary> The Type property of the Entity Question<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Question"."Type"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String Type
		{
			get { return (System.String)GetValue((int)QuestionFieldIndex.Type, true); }
			set	{ SetValue((int)QuestionFieldIndex.Type, value, true); }
		}

		/// <summary> Retrieves all related entities of type 'QuestionnaireQuestionEntity' using a relation of type '1:n'.<br/><br/>
		/// </summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiQuestionnaireQuestion()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.QuestionnaireQuestionCollection QuestionnaireQuestion
		{
			get	{ return GetMultiQuestionnaireQuestion(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for QuestionnaireQuestion. When set to true, QuestionnaireQuestion is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time QuestionnaireQuestion is accessed. You can always execute/ a forced fetch by calling GetMultiQuestionnaireQuestion(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchQuestionnaireQuestion
		{
			get	{ return _alwaysFetchQuestionnaireQuestion; }
			set	{ _alwaysFetchQuestionnaireQuestion = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property QuestionnaireQuestion already has been fetched. Setting this property to false when QuestionnaireQuestion has been fetched
		/// will clear the QuestionnaireQuestion collection well. Setting this property to true while QuestionnaireQuestion hasn't been fetched disables lazy loading for QuestionnaireQuestion</summary>
		[Browsable(false)]
		public bool AlreadyFetchedQuestionnaireQuestion
		{
			get { return _alreadyFetchedQuestionnaireQuestion;}
			set 
			{
				if(_alreadyFetchedQuestionnaireQuestion && !value && (_questionnaireQuestion != null))
				{
					_questionnaireQuestion.Clear();
				}
				_alreadyFetchedQuestionnaireQuestion = value;
			}
		}

		/// <summary> Gets / sets related entity of type 'ConsultQuestionEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.<br/><br/></summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleConsultQuestion()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual ConsultQuestionEntity ConsultQuestion
		{
			get	{ return GetSingleConsultQuestion(false); }
			set
			{
				if(this.IsDeserializing)
				{
					SetupSyncConsultQuestion(value);
				}
				else
				{
					if(value==null)
					{
						bool raisePropertyChanged = (_consultQuestion !=null);
						DesetupSyncConsultQuestion(true, true);
						if(raisePropertyChanged)
						{
							OnPropertyChanged("ConsultQuestion");
						}
					}
					else
					{
						if(_consultQuestion!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Question");
							SetupSyncConsultQuestion(value);
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for ConsultQuestion. When set to true, ConsultQuestion is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time ConsultQuestion is accessed. You can always execute a forced fetch by calling GetSingleConsultQuestion(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchConsultQuestion
		{
			get	{ return _alwaysFetchConsultQuestion; }
			set	{ _alwaysFetchConsultQuestion = value; }	
		}
		
		/// <summary>Gets / Sets the lazy loading flag if the property ConsultQuestion already has been fetched. Setting this property to false when ConsultQuestion has been fetched
		/// will set ConsultQuestion to null as well. Setting this property to true while ConsultQuestion hasn't been fetched disables lazy loading for ConsultQuestion</summary>
		[Browsable(false)]
		public bool AlreadyFetchedConsultQuestion
		{
			get { return _alreadyFetchedConsultQuestion;}
			set 
			{
				if(_alreadyFetchedConsultQuestion && !value)
				{
					this.ConsultQuestion = null;
				}
				_alreadyFetchedConsultQuestion = value;
			}
		}
		
		/// <summary> Gets / sets the flag for what to do if the related entity available through the property ConsultQuestion is not found
		/// in the database. When set to true, ConsultQuestion will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: false.</summary>
		[Browsable(false)]
		public bool ConsultQuestionReturnsNewIfNotFound
		{
			get	{ return _consultQuestionReturnsNewIfNotFound; }
			set	{ _consultQuestionReturnsNewIfNotFound = value; }	
		}
		/// <summary> Gets / sets related entity of type 'DateQuestionEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.<br/><br/></summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleDateQuestion()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual DateQuestionEntity DateQuestion
		{
			get	{ return GetSingleDateQuestion(false); }
			set
			{
				if(this.IsDeserializing)
				{
					SetupSyncDateQuestion(value);
				}
				else
				{
					if(value==null)
					{
						bool raisePropertyChanged = (_dateQuestion !=null);
						DesetupSyncDateQuestion(true, true);
						if(raisePropertyChanged)
						{
							OnPropertyChanged("DateQuestion");
						}
					}
					else
					{
						if(_dateQuestion!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Question");
							SetupSyncDateQuestion(value);
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for DateQuestion. When set to true, DateQuestion is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time DateQuestion is accessed. You can always execute a forced fetch by calling GetSingleDateQuestion(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchDateQuestion
		{
			get	{ return _alwaysFetchDateQuestion; }
			set	{ _alwaysFetchDateQuestion = value; }	
		}
		
		/// <summary>Gets / Sets the lazy loading flag if the property DateQuestion already has been fetched. Setting this property to false when DateQuestion has been fetched
		/// will set DateQuestion to null as well. Setting this property to true while DateQuestion hasn't been fetched disables lazy loading for DateQuestion</summary>
		[Browsable(false)]
		public bool AlreadyFetchedDateQuestion
		{
			get { return _alreadyFetchedDateQuestion;}
			set 
			{
				if(_alreadyFetchedDateQuestion && !value)
				{
					this.DateQuestion = null;
				}
				_alreadyFetchedDateQuestion = value;
			}
		}
		
		/// <summary> Gets / sets the flag for what to do if the related entity available through the property DateQuestion is not found
		/// in the database. When set to true, DateQuestion will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: false.</summary>
		[Browsable(false)]
		public bool DateQuestionReturnsNewIfNotFound
		{
			get	{ return _dateQuestionReturnsNewIfNotFound; }
			set	{ _dateQuestionReturnsNewIfNotFound = value; }	
		}
		/// <summary> Gets / sets related entity of type 'MultiChoiceQuestionEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.<br/><br/></summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleMultiChoiceQuestion()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual MultiChoiceQuestionEntity MultiChoiceQuestion
		{
			get	{ return GetSingleMultiChoiceQuestion(false); }
			set
			{
				if(this.IsDeserializing)
				{
					SetupSyncMultiChoiceQuestion(value);
				}
				else
				{
					if(value==null)
					{
						bool raisePropertyChanged = (_multiChoiceQuestion !=null);
						DesetupSyncMultiChoiceQuestion(true, true);
						if(raisePropertyChanged)
						{
							OnPropertyChanged("MultiChoiceQuestion");
						}
					}
					else
					{
						if(_multiChoiceQuestion!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Question");
							SetupSyncMultiChoiceQuestion(value);
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for MultiChoiceQuestion. When set to true, MultiChoiceQuestion is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time MultiChoiceQuestion is accessed. You can always execute a forced fetch by calling GetSingleMultiChoiceQuestion(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchMultiChoiceQuestion
		{
			get	{ return _alwaysFetchMultiChoiceQuestion; }
			set	{ _alwaysFetchMultiChoiceQuestion = value; }	
		}
		
		/// <summary>Gets / Sets the lazy loading flag if the property MultiChoiceQuestion already has been fetched. Setting this property to false when MultiChoiceQuestion has been fetched
		/// will set MultiChoiceQuestion to null as well. Setting this property to true while MultiChoiceQuestion hasn't been fetched disables lazy loading for MultiChoiceQuestion</summary>
		[Browsable(false)]
		public bool AlreadyFetchedMultiChoiceQuestion
		{
			get { return _alreadyFetchedMultiChoiceQuestion;}
			set 
			{
				if(_alreadyFetchedMultiChoiceQuestion && !value)
				{
					this.MultiChoiceQuestion = null;
				}
				_alreadyFetchedMultiChoiceQuestion = value;
			}
		}
		
		/// <summary> Gets / sets the flag for what to do if the related entity available through the property MultiChoiceQuestion is not found
		/// in the database. When set to true, MultiChoiceQuestion will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: false.</summary>
		[Browsable(false)]
		public bool MultiChoiceQuestionReturnsNewIfNotFound
		{
			get	{ return _multiChoiceQuestionReturnsNewIfNotFound; }
			set	{ _multiChoiceQuestionReturnsNewIfNotFound = value; }	
		}
		/// <summary> Gets / sets related entity of type 'OpenQuestionEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.<br/><br/></summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleOpenQuestion()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual OpenQuestionEntity OpenQuestion
		{
			get	{ return GetSingleOpenQuestion(false); }
			set
			{
				if(this.IsDeserializing)
				{
					SetupSyncOpenQuestion(value);
				}
				else
				{
					if(value==null)
					{
						bool raisePropertyChanged = (_openQuestion !=null);
						DesetupSyncOpenQuestion(true, true);
						if(raisePropertyChanged)
						{
							OnPropertyChanged("OpenQuestion");
						}
					}
					else
					{
						if(_openQuestion!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Question");
							SetupSyncOpenQuestion(value);
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for OpenQuestion. When set to true, OpenQuestion is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time OpenQuestion is accessed. You can always execute a forced fetch by calling GetSingleOpenQuestion(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchOpenQuestion
		{
			get	{ return _alwaysFetchOpenQuestion; }
			set	{ _alwaysFetchOpenQuestion = value; }	
		}
		
		/// <summary>Gets / Sets the lazy loading flag if the property OpenQuestion already has been fetched. Setting this property to false when OpenQuestion has been fetched
		/// will set OpenQuestion to null as well. Setting this property to true while OpenQuestion hasn't been fetched disables lazy loading for OpenQuestion</summary>
		[Browsable(false)]
		public bool AlreadyFetchedOpenQuestion
		{
			get { return _alreadyFetchedOpenQuestion;}
			set 
			{
				if(_alreadyFetchedOpenQuestion && !value)
				{
					this.OpenQuestion = null;
				}
				_alreadyFetchedOpenQuestion = value;
			}
		}
		
		/// <summary> Gets / sets the flag for what to do if the related entity available through the property OpenQuestion is not found
		/// in the database. When set to true, OpenQuestion will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: false.</summary>
		[Browsable(false)]
		public bool OpenQuestionReturnsNewIfNotFound
		{
			get	{ return _openQuestionReturnsNewIfNotFound; }
			set	{ _openQuestionReturnsNewIfNotFound = value; }	
		}
		/// <summary> Gets / sets related entity of type 'QuestionnaireEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.<br/><br/></summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleQuestionnaire()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual QuestionnaireEntity Questionnaire
		{
			get	{ return GetSingleQuestionnaire(false); }
			set
			{
				if(this.IsDeserializing)
				{
					SetupSyncQuestionnaire(value);
				}
				else
				{
					if(value==null)
					{
						bool raisePropertyChanged = (_questionnaire !=null);
						DesetupSyncQuestionnaire(true, true);
						if(raisePropertyChanged)
						{
							OnPropertyChanged("Questionnaire");
						}
					}
					else
					{
						if(_questionnaire!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Question");
							SetupSyncQuestionnaire(value);
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for Questionnaire. When set to true, Questionnaire is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Questionnaire is accessed. You can always execute a forced fetch by calling GetSingleQuestionnaire(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchQuestionnaire
		{
			get	{ return _alwaysFetchQuestionnaire; }
			set	{ _alwaysFetchQuestionnaire = value; }	
		}
		
		/// <summary>Gets / Sets the lazy loading flag if the property Questionnaire already has been fetched. Setting this property to false when Questionnaire has been fetched
		/// will set Questionnaire to null as well. Setting this property to true while Questionnaire hasn't been fetched disables lazy loading for Questionnaire</summary>
		[Browsable(false)]
		public bool AlreadyFetchedQuestionnaire
		{
			get { return _alreadyFetchedQuestionnaire;}
			set 
			{
				if(_alreadyFetchedQuestionnaire && !value)
				{
					this.Questionnaire = null;
				}
				_alreadyFetchedQuestionnaire = value;
			}
		}
		
		/// <summary> Gets / sets the flag for what to do if the related entity available through the property Questionnaire is not found
		/// in the database. When set to true, Questionnaire will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: false.</summary>
		[Browsable(false)]
		public bool QuestionnaireReturnsNewIfNotFound
		{
			get	{ return _questionnaireReturnsNewIfNotFound; }
			set	{ _questionnaireReturnsNewIfNotFound = value; }	
		}
 
		/// <summary> Gets / Sets the value of the related field this.DateQuestion.Answer.<br/><br/></summary>
		public virtual Nullable<System.DateTime> DateAnswer
		{
			get
			{
				DateQuestionEntity relatedEntity = this.DateQuestion;
				return relatedEntity==null ? (Nullable<System.DateTime>)TypeDefaultValue.GetDefaultValue(typeof(Nullable<System.DateTime>)) : relatedEntity.Answer;
			}
			set
			{
				DateQuestionEntity relatedEntity = this.DateQuestion;
				if(relatedEntity!=null)
				{
					relatedEntity.Answer = value;
				}				
			}
		}
 
		/// <summary> Gets / Sets the value of the related field this.MultiChoiceQuestion.Answer.<br/><br/></summary>
		public virtual System.String MultiAnswer
		{
			get
			{
				MultiChoiceQuestionEntity relatedEntity = this.MultiChoiceQuestion;
				return relatedEntity==null ? (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String)) : relatedEntity.Answer;
			}
			set
			{
				MultiChoiceQuestionEntity relatedEntity = this.MultiChoiceQuestion;
				if(relatedEntity!=null)
				{
					relatedEntity.Answer = value;
				}				
			}
		}
 
		/// <summary> Gets / Sets the value of the related field this.MultiChoiceQuestion.Choices.<br/><br/></summary>
		public virtual System.String MultiChoices
		{
			get
			{
				MultiChoiceQuestionEntity relatedEntity = this.MultiChoiceQuestion;
				return relatedEntity==null ? (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String)) : relatedEntity.Choices;
			}
			set
			{
				MultiChoiceQuestionEntity relatedEntity = this.MultiChoiceQuestion;
				if(relatedEntity!=null)
				{
					relatedEntity.Choices = value;
				}				
			}
		}
 
		/// <summary> Gets / Sets the value of the related field this.MultiChoiceQuestion.PatientRemarks.<br/><br/></summary>
		public virtual System.String MultiPatientRemarks
		{
			get
			{
				MultiChoiceQuestionEntity relatedEntity = this.MultiChoiceQuestion;
				return relatedEntity==null ? (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String)) : relatedEntity.PatientRemarks;
			}
			set
			{
				MultiChoiceQuestionEntity relatedEntity = this.MultiChoiceQuestion;
				if(relatedEntity!=null)
				{
					relatedEntity.PatientRemarks = value;
				}				
			}
		}
 
		/// <summary> Gets / Sets the value of the related field this.OpenQuestion.Answer.<br/><br/></summary>
		public virtual System.String OpenAnswer
		{
			get
			{
				OpenQuestionEntity relatedEntity = this.OpenQuestion;
				return relatedEntity==null ? (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String)) : relatedEntity.Answer;
			}
			set
			{
				OpenQuestionEntity relatedEntity = this.OpenQuestion;
				if(relatedEntity!=null)
				{
					relatedEntity.Answer = value;
				}				
			}
		}

		/// <summary> Gets or sets a value indicating whether this entity is a subtype</summary>
		protected override bool LLBLGenProIsSubType
		{
			get { return false;}
		}

		/// <summary> Gets the type of the hierarchy this entity is in. </summary>
		[System.ComponentModel.Browsable(false), XmlIgnore]
		protected override InheritanceHierarchyType LLBLGenProIsInHierarchyOfType
		{
			get { return InheritanceHierarchyType.None;}
		}
		
		/// <summary>Returns the MyHealthOnline.Dal.Generated.EntityType enum value for this entity.</summary>
		[Browsable(false), XmlIgnore]
		protected override int LLBLGenProEntityTypeValue 
		{ 
			get { return (int)MyHealthOnline.Dal.Generated.EntityType.QuestionEntity; }
		}

		#endregion


		#region Custom Entity code
		
		// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
		// __LLBLGENPRO_USER_CODE_REGION_END
		
		#endregion

		#region Included code

		#endregion
	}
}
